﻿using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L4_Dialog.ViewModels
{
    public class EditDialogViewModel : BindableBase, IDialogAware
    {
        public string Title => "消息";

        private string _text;
        /// <summary>
        /// 文本框内容
        /// </summary>
        public string Text
        {
            get { return _text; }
            set { SetProperty(ref _text, value); }
        }

        public DelegateCommand Confirm { get; set; }
        void ExcuteConfirm()
        {
            DialogParameters dialogParameters = new DialogParameters();
            dialogParameters.Add("title", Text);

            DialogResult dr = new DialogResult();
            dr.Result = ButtonResult.OK;
            dr.Parameters = dialogParameters;
            dr.Exception = new System.Exception("测试");

            RequestClose.Invoke(dialogParameters, ButtonResult.OK);
        }

        public DelegateCommand Cancel { get; set; }
        void ExcuteCancel()
        {
            RequestClose.Invoke(ButtonResult.Cancel);
        }

        public EditDialogViewModel()
        {
            Confirm = new DelegateCommand(ExcuteConfirm);
            Cancel = new DelegateCommand(ExcuteCancel);
        }

        public DialogCloseListener RequestClose { get; }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            Text = parameters.GetValue<string>("title");
        }
    }
}